package two.chapter_1.c1_2;

public class Accmulator {

    private int N;
    private double s;//方差
    private double m;//平均数
    public void addDataValue(double x){
        N++;

        s=s+1.0*(N-1)/N*(x-m)*(x-m);

        m=m+(x-m)/N;
    }

    public double mean(){
        return m;
    }
    /**
     * 方差
     * @return
     */
    public double var(){
        return s/(N-1);
    }
    @Override
    public String toString() {
        return "Mean ("+N+" values):"+String.format("%7.5f",mean());
    }
}
